//
//  UIDevice+UIDeviceEX.m
//  WuCha
//
//  Created by michael shen on 16/2/22.
//  Copyright © 2016年 youzi. All rights reserved.
//

#import "UIDevice+UIDeviceEX.h"
#import "SSKeychain.h"
#import "OpenUDID.h"

@implementation UIDevice (UIDeviceEX)

- (NSString *) uniqueDeviceIdentifier {
    NSString *deviceId = nil;
    @synchronized(self){
        /** 初始化一个保存用户帐号的KeychainItemWrapper */
        //        KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"DeviceID"
        //                                                                           accessGroup:@"DeviceID.com.unicom.wo116114"];
        deviceId = [SSKeychain passwordForService:@"DeviceID.com.phicomm.EContract" account:@"DeviceID"];
        if ([deviceId length] == 0) {
            //生成OpenUDID
            deviceId = [OpenUDID value];
            if ([deviceId length] > 0) {
                //保存数据
                [SSKeychain setPassword:deviceId forService:@"DeviceID.com.phicomm.EContract" account:@"DeviceID"];
            }
        }
    }
    return deviceId;
}

@end
